﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using AMPLibrary;
using AMPLibrary.Controllers;

namespace MediaLibrary.Controls
{
    /// <summary>
    /// Interaction logic for PlaylistOptionsPage.xaml
    /// </summary>
    public partial class PlaylistOptionsPage : Page
    {
        public PlaylistOptionsPage()
        {
            InitializeComponent();

            BindContent();
        }

        private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            Settings.PlaylistFolderMusic = string.Empty;
            BindContent();

            WatchFolderController watchFolderController = WatchFolderController.GetWatchFolderController();
            watchFolderController.Start(Settings.WatchFolderScanMode);
        }

        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Settings.PlaylistFolderVideo = string.Empty;
            BindContent();

            WatchFolderController watchFolderController = WatchFolderController.GetWatchFolderController();
            watchFolderController.Start(Settings.WatchFolderScanMode);
        }

        private void addMusicPlaylistFolderButton_Click(object sender, RoutedEventArgs e)
        {
            ListBoxItem lbi = (ListBoxItem)musicListBox.Items[0];

            if (lbi.Visibility != Visibility.Hidden)
            {
                System.Windows.MessageBox.Show("You cannot define another Music Playlist Watch Folder", "Error");
                return;
            }

            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                if (Settings.PlaylistFolderMusic == string.Empty)
                    Settings.PlaylistFolderMusic = folderBrowserDialog.SelectedPath;
            }

            BindContent();

            WatchFolderController watchFolderController = WatchFolderController.GetWatchFolderController();
            watchFolderController.Start(Settings.WatchFolderScanMode);
        }

        private void addVideoPlaylistFolderButton_Click(object sender, RoutedEventArgs e)
        {
            ListBoxItem lbi = (ListBoxItem)videoListBox.Items[0];

            if (lbi.Visibility != Visibility.Hidden)
            {
                System.Windows.MessageBox.Show("You cannot define another Video Playlist Watch Folder", "Error");
                return;
            }

            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();

            if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
            {
                if (Settings.PlaylistFolderVideo == string.Empty)
                    Settings.PlaylistFolderVideo = folderBrowserDialog.SelectedPath;
            }

            BindContent();

            WatchFolderController watchFolderController = WatchFolderController.GetWatchFolderController();
            watchFolderController.Start(Settings.WatchFolderScanMode);
        }

        private void BindContent()
        {
            TextBlock tb = new TextBlock();
            tb.Text = Settings.PlaylistFolderMusic;
            watchFolderMusicPlaylistLabel.Content = tb;

            if (tb.Text == string.Empty)
            {
                ListBoxItem lbi = (ListBoxItem)musicListBox.Items[0];
                lbi.Visibility = Visibility.Hidden;
            }
            else
            {
                ListBoxItem lbi = (ListBoxItem)musicListBox.Items[0];
                lbi.Visibility = Visibility.Visible;
            }

            tb = new TextBlock();
            tb.Text = Settings.PlaylistFolderVideo;
            watchFolderVideoPlaylistLabel.Content = tb;

            if (tb.Text == string.Empty)
            {
                ListBoxItem lbi = (ListBoxItem)videoListBox.Items[0];
                lbi.Visibility = Visibility.Hidden;
            }
            else
            {
                ListBoxItem lbi = (ListBoxItem)videoListBox.Items[0];
                lbi.Visibility = Visibility.Visible;
            }
        }
    }
}
